//
//  NSURL+convenience.m
//  KFD
//
//  Created by JIRENTIANXIANG on 6/5/15.
//  Copyright (c) 2015 KFD. All rights reserved.
//

#import "NSURL+convenience.h"
#import "KFDStringConcatenator.h"
#import "KFDEncryptor.h"

@implementation NSURL (convenience)

+(NSURL*)urlWithBaseURL:(NSString *)baseURL parameters:(NSDictionary *)parameters
{
    if (parameters&&parameters.count>0) {
        NSString* parameterList=[KFDEncryptor autoSignedParameterListForParameters:parameters];
        NSURL* url=[NSURL URLWithString:[NSString stringWithFormat:@"%@?%@",baseURL,parameterList]];
        return url;
    }else{
        return [NSURL URLWithString:baseURL];
    }
}

+(NSURL*)urlWithBaseURL:(NSString *)baseURL parameters:(NSDictionary *)parameters signature:(NSString *)signature
{
    if (parameters&&parameters.count>0) {
        NSString* parameterList=[KFDEncryptor signedParameterListForParameters:parameters withSignature:signature];
        NSURL* url=[NSURL URLWithString:[NSString stringWithFormat:@"%@?%@",baseURL,parameterList]];
        return url;
    }else{
        return [NSURL URLWithString:baseURL];
    }
}

@end
